<?php

namespace app\admin\model;

use think\Model;

class Supplier extends Model
{
    // 表名
    protected $name = 'supplier';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    
    // 追加属性
    protected $append = [
        'stime_text'
    ];
    
    public function getTypeList(){
        $model = new Supply();
        $list = $model->order('listorder asc,id asc')->select();
        return array_column(collection($list)->toArray(),'name','id');

    }
    



    public function getStimeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['stime'];
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setStimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }


    public function supply()
    {
        return $this->belongsTo('Supply', 'type', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
